package com.cola.demo.config;

import com.cola.demo.dao.UserDao;
import com.cola.demo.dao.impl.UserDaoCache;
import com.cola.demo.dao.impl.UserDaoNormal;
import com.cola.demo.service.UserService;
import com.cola.demo.service.impl.UserServiceNormal;
import com.cola.demo.web.UserController;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.objenesis.instantiator.basic.NewInstanceInstantiator;

/**
 * @Grup:com.cola.demo.config
 * @Auther:cola
 * @Data:2021/4/20-2021-04-0:21
 * @version:1.0
 */
@Configuration
public class AppConfig {
    @Bean
    //@Primary
    //@Qualifier("normal")
    public UserDao userDaoNormal(){
        System.out.println("创建UserDaoNormal对象");
        return  new UserDaoNormal();
    }
    @Bean
    //@Qualifier("cache")
    public UserDao userDaoCache(){
        System.out.println("创建UserDaoCache对象");
        return  new UserDaoCache();
    }

    @Bean
    public UserService userServiceNormal(@Qualifier("userDaoCache") UserDao userDao){
        System.out.println("创建UserService对象");
        UserServiceNormal userService=new UserServiceNormal();
        userService.setUserdao(userDao);
        return userService;
    }

    @Bean
    public UserController userController(UserService userService){
        System.out.println("创建UserController对象");
        UserController userController=new UserController();
        userController.setUserService(userService);
        return userController;
    }
}
